package cn.alusiaor.eurekaclientarticleservice.response;

import cn.alusiaor.commonutil.ExceptionUtil;
import cn.alusiaor.eurekaclientarticleservice.constant.ResponseCodeStatus;
import cn.alusiaor.eurekaclientarticleservice.exception.CustomException;
import lombok.Data;

/**
 * @author zhuzhiping
 * @description 统一返回结果
 * @date 2021/2/4 11:06
 */

@Data
public final class CommonResult<T> {

    private Integer code;

    private String msg;

    private String error;

    private T resultBody;

    public CommonResult() {
    }

    public CommonResult(CustomException e) {
        this.code = e.getCode();
        this.msg = e.getMsg();
        this.error = ExceptionUtil.getExceptionMessage(e);
    }

    public CommonResult(String msg, Exception e) {
        this.code = ResponseCodeStatus.error;
        this.msg = msg;
        this.error = ExceptionUtil.getExceptionMessage(e);
    }


    public CommonResult(T resultBody) {
        this.code = ResponseCodeStatus.success;
        this.msg = "操作成功";
        this.resultBody = resultBody;
    }
}
